package com.dgut.courses_selecting_sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dgut.courses_selecting_sys.entity.User;
import com.dgut.courses_selecting_sys.entity.UserRole;
import com.dgut.courses_selecting_sys.mapper.UserRoleMapper;
import com.dgut.courses_selecting_sys.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yuec
 * @since 2020-08-06
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {

    @Autowired
    UserRoleMapper userRoleMapper;

    @Override
    @Cacheable(cacheNames = {"userRoles"},unless = "#result==null")
    public UserRole getDataByUserId(Long userId) {
        UserRole userRole = userRoleMapper.selectOne(new QueryWrapper<UserRole>().eq(
                "user_id",userId
        ));
        return userRole;
    }

    @Override
//    @Cacheable(cacheNames = {"ListTeachByDeptId"}, key = "#deptId")
    public List<User> teachList(int deptId) {
        List<User> list = userRoleMapper.teachList(deptId);
        return list;
    }

    @Override
//    @Cacheable(cacheNames = {"ListStuByDeptId"}, key = "#deptId")
    public List<User> stuList(int deptId) {
        List<User> lists = userRoleMapper.stuList(deptId);
        return lists;
    }

}
